<?php
/**
 * User:chendenan
 * Created On 2022/3/9 0009 19:40
 */
declare (strict_types = 1);
namespace app\admin\middleware;

class Auth {
    public function handle($request, \Closure $next){
        //前置中间件
        if( empty(session(config("admin.session_admin"))) && !preg_match("/login/",$request->pathinfo()) && !preg_match("/verify/",$request->pathinfo()) ){
            if($request->isAjax()){
                return show("请先登录",200,['url'=>url("login/index")]);
            }
            return redirect((string)url("login/index"));
        }
        $response = $next($request);
        //后置中间件
//        if( empty(session(config("admin.session_admin"))) && $request->controller() != "Login" && $request->controller() != "Verify" ){
//            if($request->isAjax()){
//                return show("请先登录",200,['url'=>url("login/index")]);
//            }
//            return redirect((string)url("login/index"));
//        }
        return $response;

    }
    public function end(\think\Response $response){
        // 回调行为
    }
}